<?php

class CategoryController extends \BaseController {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */


	public function index()
	{
		

	}


	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		//
	}


	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		$input =Input::all();
		$validationchk=Category::validation($input);
		if($validationchk->fails()){
			return $message=$validationchk->messages();//->toArray(); 
		}else{
			$user=Category::create($input);
			return "Data Added SuccessFully";
		}

	}


	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		 $Category = DB::table('category')->where('_id', $id)->first();
        if ($Category) {
            print_r($Category);
           // return Response::json(ResponseManager::getResult($feeStructure, $message));
        } else {
           return $message = 'No Match Found';
           // return Response::json(ResponseManager::getError(array(), 01, $message));
        }
	}


	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
        $Category = DB::table('category')->where('_id', $id)->first();
        if ($Category) {
            print_r($Category);
            // return Response::json(ResponseManager::getResult($feeStructure, $message));
        } else {
            return $message = 'No Match Found';
            // return Response::json(ResponseManager::getError(array(), 01, $message));
        }
    }


	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		 //$feeStructure = DB::table('feestructure')
           //     ->where('_id', $id)
             //   ->update($input);
	
		// var_dump($id);
	//$data = Category::where('_id', '=', $id) ->first(); 
		$data=DB::table('category')->where('_id',$id);
  //     $data = Category::where('_id', '=', $id) ->first(); 
		 //var_dump($data);
		
		 //$category = Category::find($id);

		$input=Input::all();
		$input['_id']=$id;
		$input['CategoryName']='111mobile123';
		$input['description']='111abcd123';
		$input['parentid']='111111';
			//$data->_id=$id;
		$lenth=count($data);
	if($lenth==1){	
		$validation=Category::validation($input);	
				if($validation->fails()){
					return $message=$validation->messages();//->toArray(); 
					return $id;
				  }else{

				  $category = DB::table('category')
			                    ->where('_id', $id)
            			        ->update($input);

					return "Data updated SuccessFully";
			}
		}else{
			return "No match Found";
		}	
	}


	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		        
       $category = DB::table('category')
			                    ->where('_id', $id);
//        var_dump($feeStructure);
        
        if($category){
          $category->delete();
        }else{
        	return "NO RECORD TO DELETE";
        }
        if ($category) {
         return   $message = 'Deleted Successfully.';
            //return Response::json(ResponseManager::getResult($feeStructureData->toArray(), $message));
        } else {
           return  $message = 'Ooopss...! Not deleted.';
            //return Response::json(ResponseManager::getError(array(), 01, $message));
        }
	}


}
